package com.shrct.businessprocess.product.impl;

import com.shrct.businessprocess.organization.RCEnterprise;
import com.shrct.businessprocess.organization.RCSupplier;
import com.shrct.businessprocess.product.RCBrand;
import com.shrct.businessprocess.product.RCIdentifiablePhysicalProductEntry;
import com.shrct.businessprocess.product.RCNormalizerService;
import com.shrct.businessprocess.product.RCProductServiceCriteria;
import com.shrct.businessprocess.product.RCServiceLevel;
import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import java.util.Date;
import org.hibernate.Query;
import org.springframework.beans.factory.BeanFactory;

public class RCProductServiceCriteriaImpl extends HQLBasedPagedQueryCriteria<RCIdentifiablePhysicalProductEntry> implements RCProductServiceCriteria {
  private String info;
  
  public String getInfo() {
    return this.info;
  }
  
  public RCProductServiceCriteria setInfo(final String info) {
    this.info = info;
    return this;			
    
  }
  
  private RCEnterprise enterprise;
  
  public RCEnterprise getEnterprise() {
    return this.enterprise;
  }
  
  public RCProductServiceCriteria setEnterprise(final RCEnterprise enterprise) {
    this.enterprise = enterprise;
    return this;			
    
  }
  
  private Boolean isReplaced;
  
  public Boolean getIsReplaced() {
    return this.isReplaced;
  }
  
  public RCProductServiceCriteria setIsReplaced(final Boolean isReplaced) {
    this.isReplaced = isReplaced;
    return this;			
    
  }
  
  private Boolean isBorrowReplaced;
  
  public Boolean getIsBorrowReplaced() {
    return this.isBorrowReplaced;
  }
  
  public RCProductServiceCriteria setIsBorrowReplaced(final Boolean isBorrowReplaced) {
    this.isBorrowReplaced = isBorrowReplaced;
    return this;			
    
  }
  
  private Date productServiceDueDateFrom;
  
  public Date getProductServiceDueDateFrom() {
    return this.productServiceDueDateFrom;
  }
  
  public RCProductServiceCriteria setProductServiceDueDateFrom(final Date productServiceDueDateFrom) {
    this.productServiceDueDateFrom = productServiceDueDateFrom;
    return this;			
    
  }
  
  private Date productServiceDueDateTo;
  
  public Date getProductServiceDueDateTo() {
    return this.productServiceDueDateTo;
  }
  
  public RCProductServiceCriteria setProductServiceDueDateTo(final Date productServiceDueDateTo) {
    this.productServiceDueDateTo = productServiceDueDateTo;
    return this;			
    
  }
  
  private Date companyServiceDueDateFrom;
  
  public Date getCompanyServiceDueDateFrom() {
    return this.companyServiceDueDateFrom;
  }
  
  public RCProductServiceCriteria setCompanyServiceDueDateFrom(final Date companyServiceDueDateFrom) {
    this.companyServiceDueDateFrom = companyServiceDueDateFrom;
    return this;			
    
  }
  
  private Date companyServiceDueDateTo;
  
  public Date getCompanyServiceDueDateTo() {
    return this.companyServiceDueDateTo;
  }
  
  public RCProductServiceCriteria setCompanyServiceDueDateTo(final Date companyServiceDueDateTo) {
    this.companyServiceDueDateTo = companyServiceDueDateTo;
    return this;			
    
  }
  
  private String projectId;
  
  public String getProjectId() {
    return this.projectId;
  }
  
  public RCProductServiceCriteria setProjectId(final String projectId) {
    this.projectId = projectId;
    return this;			
    
  }
  
  private RCBrand brand;
  
  public RCBrand getBrand() {
    return this.brand;
  }
  
  public RCProductServiceCriteria setBrand(final RCBrand brand) {
    this.brand = brand;
    return this;			
    
  }
  
  private RCSupplier supplier;
  
  public RCSupplier getSupplier() {
    return this.supplier;
  }
  
  public RCProductServiceCriteria setSupplier(final RCSupplier supplier) {
    this.supplier = supplier;
    return this;			
    
  }
  
  private RCServiceLevel companyServiceLevel;
  
  public RCServiceLevel getCompanyServiceLevel() {
    return this.companyServiceLevel;
  }
  
  public RCProductServiceCriteria setCompanyServiceLevel(final RCServiceLevel companyServiceLevel) {
    this.companyServiceLevel = companyServiceLevel;
    return this;			
    
  }
  
  private String sid;
  
  public String getSid() {
    return this.sid;
  }
  
  public RCProductServiceCriteria setSid(final String sid) {
    this.sid = sid;
    return this;			
    
  }
  
  private String code;
  
  public String getCode() {
    return this.code;
  }
  
  public RCProductServiceCriteria setCode(final String code) {
    this.code = code;
    return this;			
    
  }
  
  public void postInitialize() {
    BeanFactory _beanFactory = this.getBeanFactory();
    RCNormalizerService _bean = _beanFactory.<RCNormalizerService>getBean(RCNormalizerService.class);
    String _normalizeSid = _bean.normalizeSid(this.info);
    this.sid = _normalizeSid;
    BeanFactory _beanFactory_1 = this.getBeanFactory();
    RCNormalizerService _bean_1 = _beanFactory_1.<RCNormalizerService>getBean(RCNormalizerService.class);
    String _normalizeSid_1 = _bean_1.normalizeSid(this.info);
    this.code = _normalizeSid_1;
  }
  
  protected String buildHQLFrom() {
    return " from com.shrct.businessprocess.product.impl.RCIdentifiablePhysicalProductEntryImpl this  left join  this.logicProduct.fullServices as fullService  left join  fullService.entries as fullServiceEntry ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getEnterprise()) ){
    	hql += " and ((this.enterprise) = (:enterprise))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCode()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSid()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) ){
    	hql += " and (((((this.type.name  LIKE :info) or (this.type.details  LIKE :info)) or (this.type.normalizedCode  LIKE :code)) or (this.normalizedSid  LIKE :sid)) or (this.enterprise.name  LIKE :info))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsReplaced()) ){
    	hql += " and (((true) = (:isReplaced)) or ((this.isReplaced) = (false)))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsBorrowReplaced()) ){
    	hql += " and ((this.isBorrowReplaced) = (:isBorrowReplaced))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProductServiceDueDateTo()) ){
    	hql += " and ((this.logicProduct.currentProductService.end) <= (:productServiceDueDateTo))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProductServiceDueDateFrom()) ){
    	hql += " and ((this.logicProduct.currentProductService.end) >= (:productServiceDueDateFrom))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCompanyServiceDueDateTo()) ){
    	hql += " and ((this.logicProduct.currentCompanyService.end) <= (:companyServiceDueDateTo))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCompanyServiceDueDateFrom()) ){
    	hql += " and ((this.logicProduct.currentCompanyService.end) >= (:companyServiceDueDateFrom))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProjectId()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProjectId()) ){
    	hql += " and ((this.projectId  LIKE :projectId) or (fullServiceEntry.projectid  LIKE :projectId))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getBrand()) ){
    	hql += " and ((this.type.brand) = (:brand))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSupplier()) ){
    	hql += " and ((this.supplier) = (:supplier))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCompanyServiceLevel()) ){
    	hql += " and ((this.logicProduct.currentCompanyService.serviceInfo.serviceLevel) = (:companyServiceLevel))" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    addOrder("this.logicProduct.projectid",edu.fudan.mylang.pf.query.OrderItem.DESC);
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo())){
    	query.setParameter("info",getInfo()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getEnterprise())){
    	query.setParameter("enterprise",getEnterprise()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsReplaced())){
    	query.setParameter("isReplaced",getIsReplaced()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsBorrowReplaced())){
    	query.setParameter("isBorrowReplaced",getIsBorrowReplaced()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProductServiceDueDateFrom())){
    	query.setParameter("productServiceDueDateFrom",getProductServiceDueDateFrom()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProductServiceDueDateTo())){
    	query.setParameter("productServiceDueDateTo",getProductServiceDueDateTo()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCompanyServiceDueDateFrom())){
    	query.setParameter("companyServiceDueDateFrom",getCompanyServiceDueDateFrom()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCompanyServiceDueDateTo())){
    	query.setParameter("companyServiceDueDateTo",getCompanyServiceDueDateTo()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProjectId())){
    	query.setParameter("projectId",getProjectId()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getBrand())){
    	query.setParameter("brand",getBrand()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSupplier())){
    	query.setParameter("supplier",getSupplier()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCompanyServiceLevel())){
    	query.setParameter("companyServiceLevel",getCompanyServiceLevel()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSid())){
    	query.setParameter("sid",getSid()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCode())){
    	query.setParameter("code",getCode()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return true;
  }
  
  public RCProductServiceCriteriaImpl() {
    initOrderBys();
  }
}
